/*
 * clog_level.c
 *
 *  Created on: 2012-8-18
 *      Author: lin
 */

#include "clog_level.h"

clog_level_t *clog_level_new(uint16_t level, uint16_t syslog_levle,
        const char* name) {
    uint32_t strlen = strlen(name);
    assert(strlen <= UINT16_MAX);
    clog_level_t *log_level = zmalloc(sizeof(clog_level_t) + 2 * strlen);
    log_level->level = level;
    log_level->syslog_level = syslog_levle;
    log_level->strlen = (uint16_t) strlen;

    char * namecpy = zmalloc(sizeof(char) * strlen + 1);
    strcpy(namecpy, name);
    namecpy = strupr(namecpy);
    memcpy(log_level->str, namecpy, strlen);
    namecpy = strlwr(namecpy);
    memcpy(log_level->str + strlen, namecpy, strlen);
    zfeee(namecpy);
    return log_level;
}

clog_level_t *clog_level_dup(clog_level_t *level) {
    uint16_t strlen = level->strlen;
    clog_level_t *log_level = zmalloc(sizeof(clog_level_t) + 2 * strlen);
    log_level->level = level->level;
    log_level->syslog_level = level->syslog_level;
    log_level->strlen = strlen;
    memcpy(log_level->str, level->str, strlen);

    return log_level;
}
